import { Component, OnInit } from '@angular/core';
import {Router,ActivatedRoute} from "@angular/router";
import {RollService} from "../../../my-service/roll.service";
import {UtilService} from "../../../my-service/util.service";

@Component({
  selector: 'app-class-members',
  templateUrl: './class-members.component.html',
  styleUrls: ['./class-members.component.css'],
})
export class classMembersComponent implements OnInit {
  readImgUrl:string = null;
  codeScore:any;
  workScore:any;
  codeScoreCount:any;//计算比列
  workScoreCount:any;//计算比例
classMembers = {
  classGuid:null,
  isShowPag:false,//是否显示表格分页器
  isShowAllData:true,//是否展示全部数据，配合分页器使用
  membersData:[],//班级数据
  defaultImg:'/assets/img/image/touxiang.png',
};
  constructor(
    private routerInfo:ActivatedRoute,
    private rollServe:RollService,
    private utilServe:UtilService
  ) {
  this.readImgUrl = this.utilServe.readImgUrl;
  }
  getStudentList(){
    this.rollServe.getStudentlist(this.classMembers.classGuid).then(res=>{
      if(res.status==1){
        this.classMembers.membersData = res.data;
      }
    })
  }
  /*获取扫码互动的成绩*/
  getScoreForCode(classGuid,stuGuid){
    this.rollServe.getScoreOfStudent(classGuid,stuGuid).then(res=>{
      if(res.status ==1){
        this.codeScore = res.data.totalScore?res.data.totalScore:0;//获取扫码互动的成绩
      }else {
        this.codeScore = 0;
      }
    })
  }
  /*获取作业墙的成绩*/
  getScoreForWork(classGuid,stuGuid){
    this.rollServe.getScoreOfHomework(classGuid,stuGuid).then(res=>{
      if(res.status==1){
        this.workScore = res.data.AVGTotalScore?res.data.AVGTotalScore:0;
      }else {
        this.workScore = 0;
      }
    })
  }
  /*获取成绩模型*/
  getScoreModle(classGuid){
    this.rollServe.getScoreCountModle(classGuid).then(res=>{
      if(res.status==1){
        this.codeScoreCount = res.data[0].ScoreSegmentWeight*0.01;
        this.workScoreCount = res.data[1].ScoreSegmentWeight*0.01;
        this.workScoreCount=this.workScoreCount?this.workScoreCount:0;
        this.codeScoreCount =this.codeScoreCount?this.codeScoreCount:0;
      }
    })
  }
  ngOnInit() {
  this.classMembers.classGuid = this.routerInfo.snapshot.params.classGuid;
    this.getStudentList();
    this.utilServe.getUserInfo().then(res=>{
       if(res.status==1){
         let stuGuid = res.userGuid;
         this.getScoreForCode(this.classMembers.classGuid,stuGuid);
         this.getScoreForWork(this.classMembers.classGuid,stuGuid);
         this.getScoreModle(this.classMembers.classGuid);
       }
    })
  }
  sort($event){
    this.classMembers.membersData.reverse();
  }

}
